<template>
	<view class="content">
		<view class="header" :style="{background:$store.state.bgPrimaryColor}">
			<view class="view">
				<!-- 				<view @click="show = true">
					<text>综合报告</text>
					<u-icon name="arrow-down-fill" color="#333" size="12"></u-icon>
				</view> -->
				<view>
					<!-- 	<view @click="isShow = true"> -->
					<text>单节课程报告</text>
					<u-icon name="arrow-down-fill" color="#333" size="12"></u-icon>
				</view>
				<view @click="datetimeShow = true">
					<text>时间</text>
					<u-icon name="arrow-down-fill" color="#333" size="12"></u-icon>
				</view>
			</view>
			<!-- <u--image :showLoading="true" src="../../static/logo.png" width="32rpx" height="32rpx" radius="0"
				@click="download"></u--image> -->
		</view>
		<view class="Box">
			<view v-for="(item,index) in lists" :key="index" class="BoxView">
				<view class="BoxOne">
					<u--image :showLoading="true" :src="item.teacher.avatar" width="94rpx" height="94rpx" radius="0"
						v-if="item.teacher"></u--image>
					<view class="BoxContent">
						<view class="BoxTop marginBottom">
							<text class="title">{{item.teacher.name || ''}}</text>
						</view>
						<view class="BoxTop">
							<u--image :showLoading="true" src="../../static/Home/rqi.png" width="36rpx" height="36rpx"
								radius="0"></u--image>
							<text class="Newtitle">{{timestampToYYYYMMDD(item.reservation.date) || ''}}</text>
						</view>
					</view>
				</view>
				<button @click="linkUrl(`/pages/Mine/MyCourseReport?id=${item.id}&type=id`)"
					:style="{'background':$store.state.buttonColor}">查看报告</button>
			</view>
		</view>
		<view class="empty" v-if="lists.length == 0">
			<image src="../../static/null.png" mode="widthFix"></image>
			<text>暂时没有课程</text>
		</view>
		<u-picker :show="show" :columns="columns" keyName="title" @confirm="confirm" @cancel="show = false"></u-picker>
		<u-picker :show="show1" :columns="UserLearningTypes" keyName="title" @confirm="UserLearningTypesconfirm"
			@cancel="show1 = false"></u-picker>
		<u-picker :show="isShow" :columns="Times" keyName="title" @confirm="Timesconfirm"
			@cancel="isShow = false"></u-picker>
		<u-datetime-picker :show="datetimeShow" v-model="value1" mode="year-month" @cancel="datetimeShow = false"
			@confirm="confirmDatetime"></u-datetime-picker>
	</view>
</template>
<script>
	import {
		getReportList
	} from '../../api/Teacher.js';
	export default {
		data() {
			return {
				show: false,
				show1: false,
				isShow: false,
				datetimeShow: false,
				value1: Number(new Date()),
				columns: [],
				UserLearningTypes: [],
				Times: [],
				lists: [],
				req: {
					page: 1,
					limit: 10,
					shop_id: uni.getStorageSync('shop_id') || 1, //门店id
					month_date: '', //年月份，2024-7月份
				}
			}
		},
		onShow() {},
		onLoad() {
			this.getReportList()
		},
		methods: {
			timestampToYYYYMMDD(timestamp) {
				const date = new Date(timestamp * 1000); // 将时间戳转换为Date对象
				const year = date.getFullYear();
				const month = ("0" + (date.getMonth() + 1)).slice(-2); // 月份需要加1，且保证两位数显示
				const day = ("0" + date.getDate()).slice(-2); // 保证日期显示两位数
				return year + '-' + month + '-' + day;
			},
			/**
			@method 报告列表
			**/
			async getReportList() {
				try {
					const res = await getReportList(this.req);
					this.lists = [...res.data.data];
				} catch (err) {
					//TODO handle the exception
					console.log(err);
				}
			},
			timestampToYearMonth(timestamp) {
				const date = new Date(timestamp);
				const year = date.getFullYear();
				const month = date.getMonth() + 1; // 月份从0开始，需要加1
				return `${year}-${month < 10 ? '0' : ''}${month}`;
			},
			confirmDatetime(e) {
				this.req = {
					...this.req,
					...{
						month_date: this.timestampToYearMonth(e.value)
					}
				};
				this.datetimeShow = false;
				this.getReportList();
			},
			confirm(e) {
				console.log(e);
			},
			UserLearningTypesconfirm(e) {
				console.log(e);
			},
			Timesconfirm(e) {
				console.log(e);
			},
			/** 
			@metho 地址跳转
			*d */
			linkUrl(e, c) {
				if (this.dianji == 1) {
					uni.navigateBack()
					uni.$emit('jiaocai', {
						id: c
					})
				} else {
					uni.navigateTo({
						url: e
					});
				}
			}
		}
	}
</script>
<style scoped lang="scss">
	button::after {
		border: none;
	}

	.content {
		.header {
			width: auto;
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.view {
				width: auto;
				display: flex;
				justify-content: space-between;
				align-items: center;

				view {
					display: flex;
					align-items: center;
					margin-right: 30rpx;

					text {
						margin-right: 10rpx;
						color: #333333;
						font-size: 28rpx;
						font-weight: 600;
						font-family: PingFangSC, PingFang SC;
						text-align: left;
						font-style: normal;
					}
				}
			}
		}

		.Box {
			.BoxView {
				width: 85%;
				margin: 0px auto;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 30rpx 40rpx 30rpx 40rpx;
				margin-top: 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.BoxOne {
				display: flex;
				justify-content: space-between;

				.marginBottom {
					margin-bottom: 10rpx;
				}

				.BoxTop {
					margin-left: 20rpx;
					display: flex;
					align-items: center;

					text {
						display: block;
						font-size: 24rpx;
					}

					.title {
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						font-size: 32rpx;
						color: #333333;
						font-style: normal;
					}

					.Newtitle {
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #333333;
						font-style: normal;
						margin-left: 10rpx;
					}
				}
			}

			button {
				width: 154rpx;
				min-width: 154rpx;
				height: 60rpx;
				border-radius: 46rpx;
				margin: 0px;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				font-size: 26rpx;
			}
		}

		.empty {
			image {
				width: 100%;
			}

			text {
				display: block;
				text-align: center;
				font-family: PingFangSC, PingFang SC;
				font-weight: 600;
				font-size: 36rpx;
				color: #333333;
			}
		}

		.NewpopupBody {
			width: 550rpx;
			height: auto;
			padding-top: 70rpx;
			padding-bottom: 70rpx;
			background-color: transparent;

			.title {
				font-family: PingFangSC, PingFang SC;
				font-weight: 600;
				font-size: 36rpx;
				color: #333333;
				display: block;
				text-align: center;
			}

			.content_text {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
				display: block;
				text-align: center;
				padding-top: 30rpx;
				padding-bottom: 30rpx;
			}

			.but_flex {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 50rpx;

				.leftButton {
					width: 40%;
					font-family: PingFangSC, PingFang SC;
					font-weight: 600;
					font-size: 32rpx;
					color: #333333;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 50rpx;
					background-color: #efefef;
				}

				.rightButton {
					width: 40%;
					font-family: PingFangSC, PingFang SC;
					font-weight: 600;
					font-size: 32rpx;
					color: #fff;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 50rpx;
					background-color: #267fff;
				}
			}
		}
	}
</style>